<?php
$ma_donvi = $_POST['donvi'];
$hocvu = $_POST['dvhv'];
$ma_monhoc = $_POST['mon'];
$ma_nganh = $_POST['nganh'];
$mahdthi = $_POST['mahd'];
if(empty($ma_donvi) || empty($hocvu) || empty($ma_monhoc) || empty($ma_nganh) || empty($mahdthi)){
    header('Location: index.php?muc=tochucthi&modul=lapdsthi_filter');
}
include '../lib/BLL/TrungTamBLL.php';
include '../lib/BLL/DmMonHocBLL.php';
include '../lib/BLL/DonViHocVuBLL.php';
include '../lib/BLL/SinhVienBLL.php';
include '../lib/BLL/DmCaHocBLL.php';
include '../lib/BLL/HoiDongThiBLL.php';
include '../lib/BLL/DonViBLL.php';
include '../lib/BLL/DmNganhBLL.php';
$hoidong = new HoiDongThiBLL();



$sql="SELECT mctdt.ma_mon_ctdt FROM tbl_mon_ctdt AS mctdt
					INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
					INNER JOIN tbl_lopmon AS lm ON lm.ma_lopmon = lmctdt.ma_lopmon
					INNER JOIN tbl_ctdt AS ctdt ON mctdt.ma_ctdt = ctdt.ma_ctdt
					WHERE lm.ma_donvi = '$ma_donvi' AND lm.ma_donvihocvu = '$hocvu' AND ctdt.madm_nganh = '$ma_nganh'
					AND mctdt.ma_monhoc = '$ma_monhoc'";
 $ma_mon_ctdt = $db->getOneField($sql);

$dv = new DonViBLL();
$mh = new DmMonHocBLL();
$dvhv = new DonViHocVuBLL();
$sv = new SinhVienBLL();
$cathi = new DmCaHocBLL();
$nh = new DmNganhBLL();


$smarty->assign('mahoidong',$mahdthi);




//Get List SV
$sql0 = "SELECT lm.ngaybatdau FROM tbl_lopmon AS lm
INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lm.ma_lopmon = lmctdt.ma_lopmon
INNER JOIN  tbl_mon_ctdt AS mctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
INNER JOIN dm_monhoc AS mh ON mctdt.ma_monhoc = mh.madm_mh
WHERE lm.ma_donvi = '$ma_donvi' AND lm.ma_donvihocvu = '$hocvu'
AND mh.madm_mh = '$ma_monhoc'";
$ngaylm = $db->getList($sql0);


$sql = "SELECT dkm.ma_sv, dkm.ma_dkm, sv.hoten_sv, sv.ngaysinh_sv, dkm.ma_lopmon FROM tbl_dangkymon AS dkm
INNER JOIN tbl_sinhvien AS sv ON sv.ma_sv = dkm.ma_sv
WHERE ma_lopmon IN(SELECT lm.ma_lopmon FROM tbl_lopmon AS lm
INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lm.ma_lopmon = lmctdt.ma_lopmon
INNER JOIN  tbl_mon_ctdt AS mctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
INNER JOIN dm_monhoc AS mh ON mctdt.ma_monhoc = mh.madm_mh
WHERE lm.ma_donvi = '$ma_donvi' AND lm.ma_donvihocvu = '$hocvu'
AND mh.madm_mh = '$ma_monhoc' ORDER BY lm.ngaybatdau ASC
) AND dkm.ma_dkm NOT IN(SELECT ma_dkm FROM tbl_diemthi WHERE ma_dsthi IN(SELECT DISTINCT ma_dsthi FROM `tbl_dsthi` WHERE ma_hoidongthi = '$mahdthi' AND ma_mon_ctdt = '$ma_mon_ctdt')) ORDER BY sv.ten_sv ASC, sv.hoten_sv";
$svarr = $db->getList($sql);
$slsv = sizeof($svarr);

$donvi = $dv->getDonViInfo($ma_donvi);
$monhoc = $mh->getDmMonHoc($ma_monhoc);
$ds_dvhv = $dvhv->getListDonViHocVu();
$ds_sv = $sv->getListSinhvien();
$ds_cathi = $cathi->getListDmCaHoc();
$nganh = $nh->getNganh($ma_nganh);

$smarty->assign('madv', $ma_donvi);
$smarty->assign('mamh', $ma_monhoc);
$smarty->assign('ngaylm', $ngaylm);
$smarty->assign('monhoc',$monhoc);
$smarty->assign('nganh',$nganh);
$smarty->assign('donvi',$donvi);
$smarty->assign('sinhvien',$svarr);
$smarty->assign('hocvu',$hocvu);
$smarty->assign('ds_sv',$ds_sv);
$smarty->assign('ds_cathi',$ds_cathi);
$smarty->assign('date',date('d-m-Y'));
$smarty->assign('ma_mon_ctdt',$ma_mon_ctdt);
$smarty->assign('slsv', $slsv);
$smarty->display('tochucthi/lapdsthi.tpl');
?>